teg salt sls文件解读

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 4478

2019/06/20 00:55


salt sls文件解读

es-rpm-file:
  file.managed: #文件上传
    - name: /opt/elasticsearch-2.4.2.rpm   #子节点文件
    - source: salt://test/es-2-4/elasticsearch-2.4.2.rpm #主节点文件
    - user: root  #子节点上文件属主
    - group: root #子节点上文件属主
    - mode: 755 #授权

es-install:
  cmd.run:
    - cwd: /opt #运行路径
    - names:
      - yum -y localinstall elasticsearch-2.4.2.rpm #运行命令
    - unless: test ! -z `rpm -qa elasticsearch` #返回成功0则不执行下面
    - require:                       #依赖顺序
      - file: es-rpm-file

es-mkdir:
  cmd.run:
    - cwd: /data
    - names:
      - mkdir -p /data/es
      - chown -R elasticsearch:elasticsearch /data/es
    - require:
      - cmd: es-install


es-jvm-file:
  file.managed:
    - name: /etc/sysconfig/elasticsearch
    - source: salt://test/es-2-4/elasticsearch
    - template: jinja
    - user: elasticsearch
    - group: elasticsearch
    - mode: 755
    - require:
      - cmd: es-install

es-config-file:
  file.managed:
    - name: /etc/elasticsearch/elasticsearch.yml
    - source: salt://test/es-2-4/elasticsearch.yml
    - template: jinja
    - user: elasticsearch
    - group: elasticsearch
    - mode: 755
    - require:
      - cmd: es-install

file.managed

/usr/lib/python2.7/site-packages/salt/states/file.py

def managed(name,
            source=None,
            source_hash='',
            source_hash_name=None,
            user=None,
            group=None,
            mode=None,
            template=None,
            makedirs=False,
            dir_mode=None,
            context=None,
            replace=True,
            defaults=None,
            backup='',
            show_changes=True,
            create=True,
            contents=None,
            tmp_ext='',
            contents_pillar=None,
            contents_grains=None,
            contents_newline=True,
            contents_delimiter=':',
            encoding=None,
            encoding_errors='strict',
            allow_empty=True,
            follow_symlinks=True,
            check_cmd=None,
            skip_verify=False,
            win_owner=None,
            win_perms=None,
            win_deny_perms=None,
            win_inheritance=True,
            **kwargs):

cmd.run

/usr/lib/python2.7/site-packages/salt/states/cmd.py

def run(name,
        onlyif=None,
        unless=None,
        creates=None,
        cwd=None,
        runas=None,
        shell=None,
        env=None,
        stateful=False,
        umask=None,
        output_loglevel='debug',
        quiet=False,
        timeout=None,
        ignore_timeout=False,
        use_vt=False,
        **kwargs):
    '''
    Run a command if certain circumstances are met.  Use ``cmd.wait`` if you
    want to use the ``watch`` requisite.

    name
        The command to execute, remember that the command will execute with the
        path and permissions of the salt-minion.

    onlyif
        A command to run as a check, run the named command only if the command
        passed to the ``onlyif`` option returns true

    unless
        A command to run as a check, only run the named command if the command
        passed to the ``unless`` option returns false

    cwd
        The current working directory to execute the command in, defaults to
        /root

    runas
        The user name to run the command as

    shell
        The shell to use for execution, defaults to the shell grain

    env
        A list of environment variables to be set prior to execution.

jinja语法修改配置文件

通过jinja语法修改 /etc/sysconfig/elasticsearch

...
{% if 7000 < grains['mem_total'] < 10000 %}
ES_HEAP_SIZE=4g
{% elif 5000 < grains['mem_total'] < 7000 %}
ES_HEAP_SIZE=3g
{% elif 3000 < grains['mem_total'] < 5000 %}
ES_HEAP_SIZE=2g
{% elif 1000 < grains['mem_total'] < 3000 %}
ES_HEAP_SIZE=1g
{% endif %}
...

通过jinja语法修改 /etc/elasticsearch/elasticsearch.yml

...
node.name: {{grains['fqdn']}}   <!--主机名 -->

network.publish_host: {{grains['fqdn_ip4'][0]}} <!--ip -->
...

saltstack

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1